import java.io.*;
import java.util.*;

public class Calculator {

    private List<Object> stack = null;
    private List<Object> stackOfOperators = null;
    private int nubmerOfOperator;
    private String doubleDigit = "";

    public static void main(String args []) throws IOException{
        Calculator cal = new Calculator();
        cal.print();
    }
    
    //Result is displayed in console
    private void print() throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String str;

        while(!(str = in.readLine()).equals("exit")) {
        	try {
        		verifyEachCharacter(str);
            
        		for (Object s : stack) System.out.print(s.toString() + " ");
        		System.out.println("\n"+result());
        	} catch(IndexOutOfBoundsException e) {
        		System.out.println("\nIncorrecyed symbols were entered!!!" +
        				"\nWould you enter collectly,please." +
        				"\nThe following symbols are entered: 0-9, -, +, /, *, ^, ) and (" +
        				"\nExample: 1.2-3*(4+5/6)^7");
        	} catch (NumberFormatException e) {
        		System.out.println("Maybe, you forgot about closed bracket...");
        	}
        }
    }
    
    //Each character is verified
    private void verifyEachCharacter(String str) {
    	stackOfOperators = new ArrayList<Object>();
        stack = new ArrayList<Object>();
        this.nubmerOfOperator = -1;
        int countCharacters = 1;
    	
    	int countOfBrackets = (str.toCharArray()[0] == '(') ? 0 : 1;

        char[] chars = str.toCharArray();
        String symbol;
        for (char c : chars) {
        	boolean isLastSymbol = chars.length == countCharacters;
            symbol = String.valueOf(c);
            
            setOperandToStack(symbol, isLastSymbol);

            if (symbol.equals(")")) {
            	System.out.println(stackOfOperators.size());
                while (!stackOfOperators.get(stackOfOperators.size() - 1).equals("(")) {
                    PriorityOfOperators(isLastSymbol);
                    setOperatorsToStack();
                }
                stackOfOperators.remove(stackOfOperators.size() - 1);
            } else {
            	addOperatorBeforeOpenedBracket(countOfBrackets, symbol);
            	
                if (!stack.isEmpty())
                    PriorityOfOperators(isLastSymbol);
                    setOperatorsToStackOfOperators(symbol);
            }
            countCharacters++;
        }

        int n = stackOfOperators.size();

        for (int i = 0; i <= n; i++)
            setOperatorsToStack();
    }
    
    //Operator is added if opened bra bracket
    private void addOperatorBeforeOpenedBracket(int countOfBrackets, String symbol) {
    	String lastOperator = null;
    	
    	if(symbol.equals("(")) {
    		if(!stackOfOperators.isEmpty()) {
        		lastOperator = stackOfOperators.get(stackOfOperators.size()-1).toString();
        		
        		if(stackOfOperators.size() != 1 && (lastOperator.equals("*")||lastOperator.equals("/"))) 
        			countOfBrackets++;
    		}
    		
    		while(stackOfOperators.size() != countOfBrackets && !stackOfOperators.isEmpty() && 
    				!stackOfOperators.get(stackOfOperators.size()-2).equals("(")) {
    			stack.add(stack.size(), stackOfOperators.remove(stackOfOperators.size()-2));
    		}
    		
    		countOfBrackets++;
    	}
    }
    
    //A multiplication, a division and a degree operators are verified
    private void PriorityOfOperators(boolean isLastSymbol) {
        String[] operators = {"/","*","^"};
        if(stackOfOperators.size() > 1)
            for(String operator : operators)
                if(stackOfOperators.get(stackOfOperators.size()-2).equals(operator)) {
                    setPriority(isLastSymbol);
                    break;
                }
    }
    
    /*
     * A multiplication, a division and a degree 
     * are removed from stackOfOpperators list 
     * and added to stack list
     */
    private void setPriority(boolean isLastSymbol) {
        String lastOperator = stackOfOperators.get(stackOfOperators.size()-1).toString();
            if(stackOfOperators.get(stackOfOperators.size()-2).equals("^"))
                stack.add(stack.size() ,stackOfOperators.remove(stackOfOperators.size()-2));
            else
                if(lastOperator.equals("+")||lastOperator.equals("-"))
                	if(!isLastSymbol)
                		stack.add(stack.size() ,stackOfOperators.remove(stackOfOperators.size()-2));
                	else stack.add(stack.size()-1 ,stackOfOperators.remove(stackOfOperators.size()-2));

    }
    
    //Operators are added to stackOfOperators list
    private void setOperatorsToStackOfOperators(String symbol) {
        String[] operators = {"^" ,"*", "/", "+", "-","("};
        for(String operator: operators)
            if(operator.equals(symbol))
            	if(!doubleDigit.equals("-"))
            		stackOfOperators.add(symbol);
    }
    
    //This method perform addition, subtraction, multiplication and division
    private double result() {
        double result = 0;
        while(nubmerOfOperator != 0) {
        switch (upOperatorWithStack()) {
            case '+':
                result = Double.parseDouble(stack.remove(nubmerOfOperator-2).toString()) +
                        Double.parseDouble(stack.remove(nubmerOfOperator-2).toString());
                stack.add(nubmerOfOperator - 2, result);
                break;
            case '-':
                try {
                    result = Double.parseDouble(stack.remove(nubmerOfOperator-2).toString()) -
                        Double.parseDouble(stack.remove(nubmerOfOperator-2).toString());
                    stack.add(nubmerOfOperator - 2, result);
                } catch (ArrayIndexOutOfBoundsException e){
                    System.out.print("\nResult is negative");
                }
                break;
            case '*':
                result = Double.parseDouble(stack.remove(nubmerOfOperator-2).toString()) *
                        Double.parseDouble(stack.remove(nubmerOfOperator-2).toString());
                stack.add(nubmerOfOperator - 2, result);
                break;
            case '/':
                result = Double.parseDouble(stack.remove(nubmerOfOperator-2).toString()) /
                        Double.parseDouble(stack.remove(nubmerOfOperator-2).toString());
                stack.add(nubmerOfOperator - 2, result);
                break;
            case '^':
                result = Math.pow(Double.parseDouble(stack.remove(nubmerOfOperator-2).toString()),
                        Double.parseDouble(stack.remove(nubmerOfOperator-2).toString()));
                stack.add(nubmerOfOperator - 2, result);
                break;

            default:
                break;
            }
        }

        return result;
    }

    //Digits and operators are removed from stack list 
    private char upOperatorWithStack() {
        return stack.remove(this.nubmerOfOperator = countOperatorWithStack()).toString().charAt(0);
    }
    
    // Count is implemented before the first operator
    private int countOperatorWithStack() {
        int count = 0;
        String[] operators = {"^" ,"*", "/", "+", "-"};
        for(Object operator : stack) {
            for(String obj : operators)
                if(operator.equals(obj) && obj.length() == 1) return count;
            count++;
        }
        return 0;
    }

    //Operands are set to stack
    private void setOperatorsToStack() {
        if(!stackOfOperators.isEmpty())
        	stack.add(stack.size(), stackOfOperators.remove(stackOfOperators.size()-1));
    }
    
    //Digits, point and minus are set to stack
    private void setOperandToStack(String symbol, boolean isLastSymbol) {
    	
        if(verifyDigit(symbol) && !isLastSymbol) {
        	doubleDigit += symbol;
        } else {
        	//the last symbol is added to digit
        	if(isLastSymbol && verifyDigit(symbol)) doubleDigit += symbol;
        	
        	//if the first symbol is '-' minus
            if(stack.isEmpty() && symbol.equals("-") && doubleDigit.equals(""))
            	doubleDigit += "-";
            else {
            	//Point is added if character match this point 
            	if(symbol.equals(".")) doubleDigit += ".";
            	else {
            		if(!doubleDigit.isEmpty())
            			stack.add(stack.size(), doubleDigit);
            		doubleDigit = "";
            	}
            }
        }
    }
    
    //true is returned if character is digit 
    private boolean verifyDigit(String character) {
        try {
            Double.parseDouble(character);
            return true;
        } catch (NumberFormatException e) {return false;}
    }
}
